package views;

import views.panels.PanelGeneral;
import logicBusiness.EstudianteBL;
import models.Estudiante;
import java.awt.BorderLayout;
import javax.persistence.NoResultException;
import javax.swing.JOptionPane;

/**
 *
 * @author JARR
 */
public class InterfazConsultarEstudiante extends javax.swing.JFrame {

    private EstudianteBL estudiantebo;
    private String documentoestudiante;
    private Estudiante estudiante;

    /** Creates new form InterfazConsultarEstudiante */
    public InterfazConsultarEstudiante() {
        initComponents();
        PanelGeneral panel = new PanelGeneral();
        this.add(panel, BorderLayout.SOUTH);


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jLabel21 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        PanelDatosPersonales = new javax.swing.JPanel();
        CTFechaNacimiento = new javax.swing.JTextField();
        CTGeneroEst = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        CTTelefonoEst = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        CTDNIEstudiante = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        CTDireccionEst = new javax.swing.JTextField();
        TPDatosPadres = new javax.swing.JTabbedPane();
        PanelMadre = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        CTTelMadre = new javax.swing.JTextField();
        CTNomMadre = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        CTDNIMadre = new javax.swing.JTextField();
        CTApellidosMadre = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        PanelPadre = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        CTApellidosPadre = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        CTDNIPadre = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        CTNomPadre = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        CTTelPadre = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        BBuscarEst = new javax.swing.JButton();
        CTDNIBuscar = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        BAceptar = new javax.swing.JButton();

        jButton1.setText("Aceptar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel21.setText("jLabel20");

        setTitle("Consultar estudiante");
        setResizable(false);

        jLabel1.setText("Buscar Estudiante:");

        PanelDatosPersonales.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "DATOS PERSONALES DEL ESTUDIANTE", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11), new java.awt.Color(0, 0, 255))); // NOI18N

        CTFechaNacimiento.setEditable(false);
        PanelDatosPersonales.add(CTFechaNacimiento);

        CTGeneroEst.setEditable(false);
        PanelDatosPersonales.add(CTGeneroEst);

        jLabel15.setText("Genero:");
        PanelDatosPersonales.add(jLabel15);

        jLabel16.setText("Fecha de Nacimiento:");
        PanelDatosPersonales.add(jLabel16);

        jLabel14.setText("Telefono:");
        PanelDatosPersonales.add(jLabel14);

        CTTelefonoEst.setEditable(false);
        PanelDatosPersonales.add(CTTelefonoEst);

        jLabel18.setText("Numero de documento:");
        PanelDatosPersonales.add(jLabel18);

        CTDNIEstudiante.setEditable(false);
        PanelDatosPersonales.add(CTDNIEstudiante);

        jLabel19.setText("Direccion:");
        PanelDatosPersonales.add(jLabel19);

        CTDireccionEst.setEditable(false);
        PanelDatosPersonales.add(CTDireccionEst);

        TPDatosPadres.setBackground(new java.awt.Color(0, 0, 255));
        TPDatosPadres.setForeground(new java.awt.Color(0, 0, 255));
        TPDatosPadres.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);
        TPDatosPadres.setFont(new java.awt.Font("Tahoma", 1, 11));

        jLabel13.setText("Telefono de la Madre:");

        CTTelMadre.setEditable(false);

        CTNomMadre.setEditable(false);

        jLabel12.setText("Documento de la Madre:");

        jLabel11.setText("Apellidos de la Madre:");

        CTDNIMadre.setEditable(false);

        CTApellidosMadre.setEditable(false);

        jLabel10.setText("Nombre de la Madre:");

        javax.swing.GroupLayout PanelMadreLayout = new javax.swing.GroupLayout(PanelMadre);
        PanelMadre.setLayout(PanelMadreLayout);
        PanelMadreLayout.setHorizontalGroup(
            PanelMadreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelMadreLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanelMadreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(jLabel13)
                    .addComponent(jLabel10)
                    .addComponent(jLabel12))
                .addGap(4, 4, 4)
                .addGroup(PanelMadreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(CTNomMadre, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
                    .addComponent(CTApellidosMadre, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
                    .addComponent(CTDNIMadre, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
                    .addComponent(CTTelMadre, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE))
                .addContainerGap())
        );
        PanelMadreLayout.setVerticalGroup(
            PanelMadreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelMadreLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanelMadreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(CTNomMadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PanelMadreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(CTApellidosMadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PanelMadreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CTDNIMadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PanelMadreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(CTTelMadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        TPDatosPadres.addTab("Datos de la madre", PanelMadre);

        jLabel6.setText("Nombre del Padre:");

        CTApellidosPadre.setEditable(false);

        jLabel7.setText("Apellidos del Padre:");

        CTDNIPadre.setEditable(false);

        jLabel8.setText("Documento del Padre:");

        CTNomPadre.setEditable(false);

        jLabel9.setText("Teléfono del Padre:");

        CTTelPadre.setEditable(false);

        javax.swing.GroupLayout PanelPadreLayout = new javax.swing.GroupLayout(PanelPadre);
        PanelPadre.setLayout(PanelPadreLayout);
        PanelPadreLayout.setHorizontalGroup(
            PanelPadreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelPadreLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanelPadreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 134, Short.MAX_VALUE)
                .addGroup(PanelPadreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(CTTelPadre)
                    .addComponent(CTDNIPadre)
                    .addComponent(CTApellidosPadre)
                    .addComponent(CTNomPadre, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        PanelPadreLayout.setVerticalGroup(
            PanelPadreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelPadreLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanelPadreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(CTNomPadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PanelPadreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(CTApellidosPadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PanelPadreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(CTDNIPadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PanelPadreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(CTTelPadre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(63, 63, 63))
        );

        TPDatosPadres.addTab("Datos del padre", PanelPadre);

        jLabel5.setText("Buscar estudiante por documento:");

        BBuscarEst.setFont(new java.awt.Font("Tahoma", 1, 11));
        BBuscarEst.setText("Buscar y seleccionar");
        BBuscarEst.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BBuscarEstActionPerformed(evt);
            }
        });

        BAceptar.setFont(new java.awt.Font("Tahoma", 1, 11));
        BAceptar.setText("Aceptar");
        BAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BAceptarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(TPDatosPadres, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(PanelDatosPersonales, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jLabel20, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(BBuscarEst, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CTDNIBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(22, 22, 22))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(481, Short.MAX_VALUE)
                .addComponent(BAceptar)
                .addGap(178, 178, 178))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5)
                    .addComponent(CTDNIBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel20, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BBuscarEst))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(PanelDatosPersonales, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TPDatosPadres, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(BAceptar)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void BBuscarEstActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BBuscarEstActionPerformed
        try {
            estudiantebo = new EstudianteBL();
            documentoestudiante = this.CTDNIBuscar.getText();
//            estudiante = estudiantebo.obtenerEstudiantePorDocumento(Long.parseLong(documentoestudiante));
        } catch (java.lang.NumberFormatException e) {
            JOptionPane.showMessageDialog(this,
                    "El campo de busqueda documento debe ser un numero entero no negativo",
                    "Error",
                    JOptionPane.OK_OPTION);
        } catch (NoResultException e){
            JOptionPane.showMessageDialog(this,
                    "No se han encontrado estudiantes con ese numero de documento",
                    "Error",
                    JOptionPane.OK_OPTION);
        }
        if (estudiante != null) {
            this.jLabel20.setText(estudiante.toString());
            this.documentoestudiante = estudiante.getDocestudiante();
            this.CTDNIEstudiante.setText(String.valueOf(estudiante.getDocestudiante()));
            //this.CTTelefonoEst.setText(String.valueOf(estudiante.getTelefonosId()));
            this.CTGeneroEst.setText(estudiante.getGeneroest());
            this.CTDireccionEst.setText(estudiante.getDireccionest());
            //carga los datos de padres en la interfaz
            this.CTNomPadre.setText(estudiante.getNombrespadre());
            this.CTApellidosPadre.setText(estudiante.getApellidospadre());
            this.CTDNIPadre.setText(estudiante.getDocpadre());
//            if (estudiante.getTelpadre() == -1) {
//                this.CTTelPadre.setText("Aun no se ha registrado");
//            } else {
//                this.CTTelPadre.setText(String.valueOf(estudiante.getTelpadre()));
//            }

            this.CTNomMadre.setText(estudiante.getNombresmadre());
            this.CTApellidosMadre.setText(estudiante.getApellidosmadre());
            this.CTDNIMadre.setText(estudiante.getDocmadre());
//            if (estudiante.getTelmadre() == -1) {
//                this.CTTelMadre.setText("Aun no se ha registrado");
//            } else {
//                this.CTTelMadre.setText(String.valueOf(estudiante.getTelmadre()));
//            }
            this.CTFechaNacimiento.setText(estudiante.getFechanacimientoest());
        }
    }//GEN-LAST:event_BBuscarEstActionPerformed

    private void BAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BAceptarActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_BAceptarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new InterfazConsultarEstudiante().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BAceptar;
    private javax.swing.JButton BBuscarEst;
    private javax.swing.JTextField CTApellidosMadre;
    private javax.swing.JTextField CTApellidosPadre;
    private javax.swing.JTextField CTDNIBuscar;
    private javax.swing.JTextField CTDNIEstudiante;
    private javax.swing.JTextField CTDNIMadre;
    private javax.swing.JTextField CTDNIPadre;
    private javax.swing.JTextField CTDireccionEst;
    private javax.swing.JTextField CTFechaNacimiento;
    private javax.swing.JTextField CTGeneroEst;
    private javax.swing.JTextField CTNomMadre;
    private javax.swing.JTextField CTNomPadre;
    private javax.swing.JTextField CTTelMadre;
    private javax.swing.JTextField CTTelPadre;
    private javax.swing.JTextField CTTelefonoEst;
    private javax.swing.JPanel PanelDatosPersonales;
    private javax.swing.JPanel PanelMadre;
    private javax.swing.JPanel PanelPadre;
    private javax.swing.JTabbedPane TPDatosPadres;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    // End of variables declaration//GEN-END:variables
}
